<template>
	<view>
		<!-- <view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">商品名称</view>
			<input class="main_size bold hei_text textright" type="text" disabled placeholder="請输入商品名称" v-model="name">
		</view> -->
		<view class="mainpadding_top ffffff">
			<view class="titletext bold hei_text">商品主圖（{{logoimage_arr.length}}/1）</view>
			<view class="flexleft flex_wrap">
				<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in logoimage_arr" :key="index">
					<!-- 已上传 -->
					<image class="listleftimg radius" :src="item" mode=""></image>
					<view class="deleteimg" @click="deleimage(index,logoimage,logoimage_arr)"></view>
				</view>
				<view class="itemimgBox flexcenter margin_top2" @click="uploadImgtop(logoimage,logoimage_arr,1)"
					v-if="logoimage_arr.length<1"><!-- 未上传 -->
					<image class="listleftimg radius" src="@/static/image/system/upimg.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff">
			<view class="titletext bold hei_text">商品輪播圖（{{carouselimages_arr.length}}/10）</view>
			<view class="flexleft flex_wrap">
				<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in carouselimages_arr" :key="index">
					<!-- 已上传 -->
					<image class="listleftimg radius" :src="item" mode=""></image>
					<view class="deleteimg" @click="deleimage(index,carouselimages,carouselimages_arr)"></view>
				</view>
				<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(carouselimages,carouselimages_arr,10)"
					v-if="carouselimages_arr.length<10"><!-- 未上传 -->
					<image class="listleftimg radius" src="@/static/image/system/upimg.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff">
			<view class="titletext bold hei_text">商品詳情圖（{{detailsimages_arr.length}}/5）</view>
			<view class="flexleft flex_wrap">
				<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in detailsimages_arr" :key="index">
					<!-- 已上传 -->
					<image class="listleftimg radius" :src="item" mode=""></image>
					<view class="deleteimg" @click="deleimage(index,detailsimages,detailsimages_arr)"></view>
				</view>
				<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(detailsimages,detailsimages_arr,5)"
					v-if="detailsimages_arr.length<5"><!-- 未上传 -->
					<image class="listleftimg radius" src="@/static/image/system/upimg.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff">
			<view class="flexbetween">
				<view class="titletext bold hei_text">上傳影片</view>
				<view class="flexright" @click="delevideo()" v-if="mvfile_arr">
					<text class="xiaohong">刪除影片</text>
				</view>
			</view>
			<view class="flexleft flex_wrap">
				<view class="itemimgBox flexcenter margin_top2" v-if="mvfile_arr">
					<!-- 已上传 -->
					<view class="listleftimg radius">
						<video class="radius" :src="mvfile_arr" style="width: 160rpx;height: 160rpx;"></video>
					</view>
				</view>
				<view class="itemimgBox flexcenter margin_top2" @click="upvideo()" v-if="!mvfile_arr"><!-- 未上传 -->
					<image class="listleftimg radius" src="@/static/image/system/upvideo.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">商品描述</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="請輸入" v-model="des">
		</view>
		<view class="mainpadding_top ffffff flexbetween" @click="jumpurl('/pages/workbench/yanseb')">
			<view class="titletext bold hei_text">顔色</view>
			<view class="flexright">
				<view class="radius margin_right1" v-show="font_color" style="width: 50rpx;height: 50rpx;" :style="[{ backgroundColor: font_color }]"></view>
				<view class="main_size bold hei_text margin_right1">{{font_color}}</view>
					<u-icon name="arrow-right" color="#333" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">是否上架</view>
			<u-radio-group v-model="is_grounding" placement="row" circle>
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="是" :name="1"></u-radio>
				<u-radio activeColor="#feb800" label="否" :name="0"></u-radio>
			</u-radio-group>
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">是否主商品</view>
			<u-radio-group v-model="is_main" placement="row" circle>
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="是" :name="1"></u-radio>
				<u-radio activeColor="#feb800" label="否" :name="0"></u-radio>
			</u-radio-group>
		</view>
		<view class="mainpadding_top ffffff flexbetween" v-if="shopInfo.hy_type==1">
			<view class="flexleft">
				<view class="titletext bold hei_text">選擇計時套餐</view>
				<view class="" @click="trashAll(3)">
					<u-icon name="trash" color="#ff0000" size="16"></u-icon>
				</view>
			</view>
			<view class="flexright" @click="jumpdetail('/pages/workbench/chidaob?type=1&cdbtc_ids=',cdbtc_ids)">
				<input class="main_size bold hei_text textright" type="text" placeholder="請選擇計時套餐" disabled
					v-if="!cdbtc_ids">
				<view class="main_size bold hei_text textright" v-else>已選擇</view>
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding_top ffffff">
			<view class="titletext bold hei_text">國際條碼</view>
			<u--input placeholder="請輸入編碼" style="border-color: #feb800 !important;"
				class="margin_top main_size bold hei_text" v-model="barcode">

				<u-icon name="scan" slot="suffix" color="#feb800" size="28" @click="saoma()"></u-icon>
			</u--input>
		</view>
		<view class="lineorange"></view>


		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">稅金</view>
			<u-radio-group v-model="rj_type" placement="row" circle>
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="應稅" :name="1"></u-radio>
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="零稅" :name="2"></u-radio>
				<u-radio activeColor="#feb800" label="免稅" :name="3"></u-radio>
			</u-radio-group>
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">用量單位</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="請輸入用量單位" v-model="unit">
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">計價方式</view>
			<u-radio-group v-model="jjfs" placement="row" circle>
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="買賣" :name="0"></u-radio>
				<u-radio activeColor="#feb800" label="多重計價" :name="1"></u-radio>
			</u-radio-group>
		</view>
		<view class="mainpadding_top ffffff flexbetween" v-if="jjfs==0">
			<view class="titletext bold hei_text">商品價格</view>
			<input class="main_size bold hei_text textright" type="number" placeholder="請輸入" v-model="price">
		</view>
		<view class="mainpadding_top ffffff flexbetween" v-if="jjfs==1">
			<view class="titletext bold hei_text">處理選擇</view>
			<u-radio-group v-model="is_cl" placement="row" circle>
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="計算" :name="0"></u-radio>
				<u-radio activeColor="#feb800" label="選擇" :name="1"></u-radio>
			</u-radio-group>
		</view>
		<view class="mainpadding_top ffffff flexbetween" v-if="is_cl==1 && jjfs==1">
			<view class="titletext bold hei_text">極距單位</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="請輸入單位" v-model="jj_unit">
		</view>
		<!-- 销售类别 -->
		<view class="mainpadding_top ffffff" v-if="jjfs==1">
			<view class="flexbetween">
				<view class="flexleft">
					<view class="titletext bold hei_text">銷售類別</view>
					<view class="xiaohong main_size">(新增時將會清除之前的銷售類別)</view>
				</view>
				<view class="addimg" @click="addSale"></view>
				<!-- <view class="" @click="addSale">
					<u-icon name="plus-circle-fill" color="#ff7424" size="28"></u-icon>
				</view> -->
			</view>
			<view class="bghui radius mainpadding_top" v-for="(item,index) in saleList" :key="index">
				<view class="flexbetween">
					<view class="main_size hei_text bold">名稱</view>
					<input class="main_size hei_text bold textright" type="text" placeholder="請輸入名稱"
						v-model="item.name">
				</view>
				<view class="flexbetween margin_top">
					<view class="main_size hei_text bold">基本價</view>
					<input class="main_size hei_text bold textright" type="number" placeholder="請輸入基本價"
						v-model="item.price_j">
				</view>
				<!-- <view class="flexbetween margin_top">
					<view class="main_size hui_text bold">單价</view>
					<input class="main_size hui_text bold textright" type="number" placeholder="請输入單价"
						v-model="item.price">
				</view> -->
				<view class="flexbetween margin_top">
					<view class="main_size hei_text bold">多重單價</view>
					<view class="flexleft">
						<input class="main_size hong_text bold textright borderhui"
							style="max-width: 180rpx; height: 80rpx;" type="number" placeholder="計算值"
							v-model="item.jsval" @confirm="pushmore(item)">
						<input class="main_size hong_text bold textright borderhui"
							style="max-width: 180rpx; height: 80rpx;" type="number" placeholder="單價"
							@confirm="pushmore(item)" v-model="item.moremoney">
						<view class="" @click="pushmore(item)">
							<u-icon name="plus-circle-fill" color="#ff7424" size="28"></u-icon>
						</view>
					</view>
				</view>
				<view class="flexbetween ffffff radius margin_top2" style="padding: 20rpx;"
					v-for="(ite,ind) in item.morepice" :key="ind+'more'">
					<view class="flexleft ">
						<view class="main_size hei_text bold" style="margin-right: 80rpx;">計算值：<text
								class="xiaohong main_size">{{ite.val}}</text></view>
						<view class="main_size hei_text bold">單價：<text class="xiaohong main_size">{{ite.money}}</text>
						</view>
					</view>
					<view class="" @click="item.morepice.splice(ind,1)">
						<u-icon name="trash" color="#ff0000" size="16"></u-icon>
					</view>
				</view>
				<view class="flexright margin_top" @click="delSale(item,index)">
					<u-icon name="trash" color="#333" size="16"></u-icon>
					<view class="xiaohei">刪除</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff flexbetween" v-if="shopInfo.hy_type==5">
			<view class="titletext bold hei_text">選擇公式</view>
			<view class="flexright" @click="selectRule('/pages/workbench/jisuanfs?selectType=1')">
				<input class="main_size bold hei_text textright" type="text" placeholder="請選擇公式" disabled
					v-model="shopformula_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="flexbetween ffffff mainpadding" v-if="shopInfo.hy_type==5">
			<view class="titletext bold hei_text">尺寸開關</view>
			<u-switch inactiveColor="rgb(230, 230, 230)" v-model="is_sizeFlag" activeColor="#feb800"
				@change="sizeFlagchange"></u-switch>
		</view>

		<view class="mainpadding_top ffffff flexbetween" v-if="shopInfo.hy_type==5">
			<view class="titletext bold hei_text">檔案上傳</view>
			<u-radio-group v-model="is_up" placement="row" circle @change="upFlagChange">
				<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="是" :name="1"></u-radio>
				<u-radio activeColor="#feb800" label="否" :name="0"></u-radio>
			</u-radio-group>
		</view>
		<view class="mainpadding_top ffffff" v-if="shopInfo.hy_type==5">
			<view class="flexbetween">
				<view class="titletext bold hei_text">基本尺寸</view>
				<view class="flexright">
					<input class="main_size bold hei_text textright margin_right" type="number" placeholder="請輸入基本尺寸"
						v-model="size_text">
					<view class="addimg" @click="addSize"></view>
				</view>
			</view>
			<view class="flexleft flex_wrap">
				<view class="flexcenter margin_top margin_right"
					style="padding: 5px 15rpx;text-align: center; min-width: 100rpx; border-radius: 50rpx;border: 1rpx solid #ff0000;"
					v-for="(item,index) in size" :key="index">
					<text class="margin_right">{{item}}</text>
					<view class="" @click="size.splice(index,1)">
						<u-icon name="close-circle-fill" color="#ff0000" size="20"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">基本數量</view>
			<input class="main_size bold hei_text textright" type="number" placeholder="請输入基本数量" v-model="num">
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">基本用量</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="請输入用量" v-model="cai">
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">交貨天數</view>
			<input class="main_size bold hei_text textright" type="number" placeholder="請输入天数" v-model="day">
		</view>
		<view class="lineorange"></view>
		<view class="mainpadding ffffff">
			<view class="flexbetween">
				<view class="flexleft">
					<view class="titletext bold margin_right1 hei_text">工作站</view>
					<view class="" @click="trashAll(3)">
						<u-icon name="trash" color="#ff0000" size="16"></u-icon>
					</view>
				</view>
				<view class="flexright" @click="selectgzz">
					<!-- <input class="main_size bold hei_text textright" type="text" placeholder="請選擇工作站" disabled
						v-model="shopwork_name"> -->
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
			<view style="padding: 0 10rpx;">
				<view class="margin_top1 flexbetween" v-for="item in gzzList" :key="item.id">
					<view class="main_size hei_text">{{item.name}}</view>
					<view class="huang_text main_size">{{item.tbzz}}
					<text v-show="item.tbzz && item.zd_status==1">/</text><text v-show="item.zd_status==1">轉</text></view>
				</view>
			</view>
		</view>
		<view class="lineorange"></view>
		<view class="mainpadding ffffff flexbetween" v-if="shopInfo.hy_type==5">
			<view class="flexleft">
				<view class="titletext bold margin_right1 hei_text">產品規格1</view>
				<view class="" @click="trashAll(1)">
					<u-icon name="trash" color="#ff0000" size="16"></u-icon>
				</view>
			</view>
			<view class="flexright" @click="selectRule(`/pages/workbench/shangpinggy`)">
				<input class="main_size bold hei_text textright" type="text" placeholder="請選擇產品規格1" disabled
					v-if="!sku_id.length">
				<view class="main_size bold hei_text textright" v-else>已選擇</view>
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding_top ffffff flexbetween" v-if="shopInfo.hy_type!=6">
			<view class="flexleft">
				<view class="titletext bold margin_right1 hei_text">產品規格2</view>
				<view class="" @click="trashAll(2)">
					<u-icon name="trash" color="#ff0000" size="16"></u-icon>
				</view>
			</view>
			<view class="flexright" @click="selectRule(`/pages/workbench/shangpingge`)">
				<input class="main_size bold hei_text textright" type="text" placeholder="請選擇產品規格2" disabled
					v-if="!spu_id.length">
				<view class="main_size bold hei_text textright" v-else>已選擇</view>
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding_top ffffff">
			<view class="flexbetween">
				<view class="titletext bold hei_text">客戶資料填寫</view>
				<view class="flexright">
					<input class="main_size bold hei_text textright margin_right" type="text" placeholder="請輸入"
						v-model="by_text" @confirm="addby">
					<view class="addimg" @click="addby"></view>
				</view>
			</view>
			<view class="flexleft flex_wrap">
				<view class="flexcenter margin_top margin_right"
					style="padding: 5px 15rpx;text-align: center; min-width: 100rpx; border-radius: 50rpx;border: 1rpx solid #ff0000;"
					v-for="(item,index) in sp_attr" :key="index">
					<text class="margin_right">{{item}}</text>
					<view class="" @click="sp_attr.splice(index,1)">
						<u-icon name="close-circle-fill" color="#ff0000" size="20"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="lineorange"></view>
		<view class="mainpadding ffffff flexbetween">
			<view class="titletext bold hei_text">選擇廠商</view>
			<view class="flexright" @click="selectRule('/pages/workbench/xuanzecs?type=1')">
				<input class="main_size bold hei_text textright" type="text" placeholder="請選擇廠商" disabled
					v-if="!firm_id">
				<view class="main_size bold hei_text textright" v-else>已選擇</view>
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>

		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">廠商電話</view>
			<input class="main_size bold hei_text textright" type="number" placeholder="請輸入廠商電話" v-model="phone">
		</view>
		<view class="lineorange"></view>
		<view class="mainpadding ffffff flexbetween">
			<view class="titletext bold hei_text">配送商品重量</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="請輸入重量" v-model="weight">
		</view>
		<view class="mainpadding_top ffffff flexbetween">
			<view class="titletext bold hei_text">商品配送商品材積 </view>
			<input class="main_size bold hei_text textright" type="text" placeholder="請輸入配送商品材積 " v-model="caiamass">
		</view>


		<view class="lineorange"></view>
		<view class="mainpadding ffffff flexbetween">
			<view class="titletext bold hei_text">上架時間</view>
			<view class="flexright" @click="selectRule('/pages/workbench/tianjiarq')">
				<input class="main_size bold hei_text" type="text" placeholder="請選擇" disabled=""
					style="text-align: right;">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="lineorange"></view>
		<view class="mainpadding ffffff flexbetween">
			<view class="flexleft">
				<view class="titletext bold margin_right1 hei_text">商品庫存</view>
				<view class="" @click="trashAll(5)">
					<u-icon name="trash" color="#ff0000" size="16"></u-icon>
				</view>
			</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="數量為-1時不限庫存" v-model="end_num">
		</view>
		<view class="mainpadding ffffff flexbetween">
			<view class="flexleft">
				<view class="titletext bold margin_right1 hei_text">商品限點數量</view>
				<view class="" @click="trashAll(4)">
					<u-icon name="trash" color="#ff0000" size="16"></u-icon>
				</view>
			</view>
			<input class="main_size bold hei_text textright" type="text" placeholder="數量為-1時不限" v-model="xd_num">
		</view>
		<view class="mainpadding_top ffffff">
			<view class="flexbetween">
				<view class="titletext bold hei_text">出貨須知</view>
				<view class="flexright" @click="jumpurl('/pages/workbench/chuhuoxzfl?type=1')">
					<view class="xiaohui main_size">導入</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
			<textarea placeholder="請輸入内容" maxlength="-1" class="main_size margin_top bold hei_text"
				style="height: 150rpx;width: 100%;" v-model="notice" />
		</view>
		<view class="mainpadding_top ffffff">
			<view class="flexbetween">
				<view class="titletext bold hei_text">商品購買須知</view>
				<view class="flexright" @click="jumpurl('/pages/workbench/goumaixzfl?type=1')">
					<view class="xiaohui main_size">導入</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
			<textarea placeholder="請輸入内容" maxlength="-1" class="main_size margin_top bold hei_text"
				style="height: 150rpx;width: 100%;" v-model="buy_notice" />
		</view>
		<view class="mainpadding">
			<view class="submitbtn" @click="confirm">確認</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				keywords: "",
				category_id: "",
				goodsInfo: "", //商品详情

				name: "", //商品名称
				logoimage: [], //商品主图
				logoimage_arr: [], //商品主图展示
				carouselimages: [], //商品轮播图
				carouselimages_arr: [], //商品轮播图展示
				detailsimages: [], //商品详情图
				detailsimages_arr: [], //商品详情图展示
				mvfile: "", //商品影片
				mvfile_arr: "", //商品影片展示
				saleList: [], //销售类别列表
				saleId: [], //销售类别id
				day: "", //交货天数
				num: "", //基本数量
				cai: "", //基本用量
				size: [], //基本尺寸
				unit: "", //單位
				jj_unit: "",
				is_cl: 0, //0計算，1選擇
				jjfs: "", //0，商品价格，1多重計价
				weight: "", //重量
				caiamass: "", //才积

				shopformula_id: "", //公式ID
				shopformula_name: "",
				shopwork_id: "", //工作站ID
				shopwork_name: "",
				gzzList: [],
				spu_id: [], //商品规格1id
				sku_id: [], //商品规格2id
				cdbtc_ids: "", //計時套餐id
				price: "", //价格
				firm_id: "", //廠商ID
				phone: "", //廠商电话
				barcode: "", //条形碼
				if_upFlag: 0,
				rj_type: "",
				is_up: "", //档案是否上传:0=否,1=是
				if_groundingFlag: "",
				is_grounding: "", //是否上架:0=否,1=是
				des: "",
				font_color:"",
				is_main: "",
				date: "", //上架時間
				// enddate: "", //下架時間
				is_sizeFlag: false,
				is_size: "", //尺寸开关:0=否,1=是
				end_num: "", //库存
				xd_num: "",
				notice: "", //出货須知
				buy_notice: "", //購買須知
				shop_id: uni.getStorageSync("shop_id"),
				// count: "", //销量
				size_text: "",
				shopInfo: {},
				by_text: "",
				sp_attr: [], //商品 客戶資料填寫
				goodsids: "", //需要編輯的商品ids

			}
		},
		watch: {
			jjfs(val) {
				if (val == 0) {
					this.price = ""
				} else {
					this.jj_unit = ""
					this.saleList = []
				}
			}
		},
		onLoad(options) {
			this.keywords = options.keywords
			this.category_id = options.category_id
			this.goodsids = options.goodsids
			uni.$on("checkchzx", data => {
				this.notice = data
				console.log(data, "選擇出貨須知");
			})
			uni.$on("checkgmzx", data => {
				this.buy_notice = data
				console.log(data, "選擇購買須知");
			})
			uni.$on("selectSku", data => {
				this.sku_id = data
				console.log(data, "選擇的規格1");
			})
			uni.$on("selectSpu", data => {
				this.spu_id = data
				console.log(data, "選擇的規格2");
			})
			uni.$on("checkcdbtc", data => {
				this.cdbtc_ids = data
				console.log(data, "選擇的計時套餐");
			})
			uni.$on("selectShop", data => {
				this.firm_id = data
				console.log(data, "選擇的廠商");
			})
			uni.$on("selectWorkId", data => {
				this.gzzList = data
				let shopwork_id = []
				let shopwork_name = []
				data.forEach(item => {
					shopwork_id.push(item.id)
					shopwork_name.push(item.name)
				})
				this.shopwork_id = shopwork_id.join()
				this.shopwork_name = shopwork_name.join()
			})
			uni.$on("selectFormula", data => {
				this.shopformula_id = data.id
				this.shopformula_name = data.name
				console.log(data, "選擇的計算管道");
			})
			uni.$on("ywmcode", data => {
				this.barcode = data
				console.log(data, "國際條碼掃描");
			})
			uni.$on("ywmcode", data => {
				this.barcode = data
				console.log(data, "國際條碼掃描");
			})
			uni.$on("checkColor", data => {
				this.font_color = data
				console.log(data, "選擇顔色");
			})
			this.getshopDetail()
		},
		onUnload() {
			uni.$off("checkgmzx")
			uni.$off("checkchzx")
			uni.$off("selectSku")
			uni.$off("selectSpu")
			uni.$off("selectShop")
			uni.$off("selectWorkId")
			uni.$off("selectFormula")
			uni.$off("ywmcode")
			uni.$off("checkcdbtc")
			uni.$off("checkColor")
		},
		methods: {
			selectgzz() {
				let data = {
					type: 1,
					gzzList: this.gzzList,
				}
				uni.navigateTo({
					url: "/pages/workbench/gongzuot?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			uploadImgtop(upImgs, upImgs_arr, value) {
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相機', '相簿'],
					success: function(res) {
						// 選擇相機走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_arr)
								}
							}).catch(err => {});
						}
						// 選擇相簿走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_arr)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg, upImgs_arr) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					upImg.push(res.url)
					let image_item = res.fullurl;
					upImgs_arr.push(image_item);
					if (this.carouselimages.length < 10) {
						this.carouselimages.push(res.url)
						this.carouselimages_arr.push(image_item)
					}

				}).catch(err => {});
			},
			addby() {
				if (this.by_text == "") {
					return false
				}
				this.sp_attr.push(this.by_text)
				this.by_text = ""
			},
			trashAll(val) {
				this.http.modal('提示', "是否將全部內容刪除 ", true, (resp) => {
					if (resp) {
						uni.showLoading({
							mask: true,
							title: "請稍後"
						})
						let data = {
							category_id: this.category_id, //商品id	
							keywords: this.keywords, //商品id
							shop_id: this.shop_id,
							type: val
						}
						this.http.request("/api/goods/delGoodsInfo", 'POST', data).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.http.toast("刪除成功")
							} else {
								this.http.toast(res.msg)
							}
						})
					}
				})
			},
			getshopDetail() {
				this.http.request("/api/shop/Shopdeail", 'POST', {
					shop_id: uni.getStorageSync("shop_id")
				}).then(res => {
					this.shopInfo = res.data
				})
			},
			saoma() {
				uni.navigateTo({
					url: "/pages/workbench/scanywcode"
				})
			},
			pushmore(item) {
				if (item.jsval == "") {
					this.http.toast("請輸入計算值")
					return false
				}
				if (item.moremoney == "") {
					this.http.toast("請輸入單價")
					return false
				}
				item.morepice.push({
					money: item.moremoney,
					val: item.jsval
				})
				item.moremoney = ""
				item.jsval = ""
			},
			selectRule(url) {
				uni.navigateTo({
					url
				})
			},
			deleimage(i, upimg, arr) { //刪除图片
				upimg.splice(i, 1)
				arr.splice(i, 1)
			},
			upvideo() { //上传影片
				let uploadFile = ''
				let _this = this;
				// 1.選擇要上传的影片
				uni.chooseVideo({
					maxDuration: 60, // 拍摄影片最长拍摄時間，單位秒。最长支持 60 秒。
					sourceType: ['album', 'camera'], // album 从相簿选影片，camera 使用相機拍摄，默认为：['album', 'camera']
					success: function(res) {
						_this.uploadImageServicet(res.tempFilePath)
					}
				});
			},
			delevideo() {
				this.mvfile = ""
				this.mvfile_arr = ""
			},
			uploadImageServicet(url) {
				let _this = this;
				this.http.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.mvfile = res.url
					this.mvfile_arr = image_item
				}).catch(err => {});
			},
			addSize() {
				this.size.push(this.size_text)
				this.size_text = []
			},
			addSale() { //添加销售类别
				this.saleList.push({
					id: "", //销售类别id
					name: "", //名称
					jsval: "",
					moremoney: "",
					morepice: [],
					price_j: "", //基本价
				})
			},
			delSale(item, index) { //刪除销售类别
				this.saleList.splice(index, 1)
				if (item.id) {
					this.getDelSale(item.id)
				} else {
					this.http.toast("刪除成功！")
				}
			},
			async getDelSale(id) {
				let res = await this.http.request("/api/goods/delSale", 'POST', {
					id
				})
				if (res.code == 1) {
					this.http.toast("刪除成功！")
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			upFlagChange(e) { //档案上传
				this.is_up = e
			},
			sizeFlagchange(e) { //尺寸开关
				this.is_size = e ? 1 : 0
			},
			confirm() { //確認
				if (this.saleList.length) {
					this.saleList.forEach((item, index) => {
						this.submitSale(item.id, item.name, item.morepice, item.price_j, index)
					})
				} else {
					this.submit()
				}
			},
			async submitSale(id, name, morepice, price_j, index) { //添加销售类别
				let res = await this.http.request("/api/goods/addSale", 'POST', {
					id, //销售类别id
					name, //名称
					// price, //單价
					price_j, //基本价
				})
				if (res.code == 1) {
					if (res.data !== 1) {
						this.saleId.push(Number(res.data))
						let resp = await this.http.request("/api/goods/addsalempney", 'POST', {
							sale_id: res.data, //销售类别id
							morepice
						})
					} else {
						let resp = await this.http.request("/api/goods/addsalempney", 'POST', {
							sale_id: id, //销售类别id
							morepice
						})
					}
					if (index == this.saleList.length - 1) {
						this.submit()
					}
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async submit() { //编辑商品提交
				let _this = this
				// if (!this.firm_id && !this.phone) {
				// 	this.http.toast("請输入廠商电话！")
				// }
				// if (this.shopwork_id == "") {
				// 	this.http.toast("請選擇工作站")
				// 	return false
				// }
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				let res = await this.http.request("/api/goods/editsGoods", 'POST', {
					category_id: this.category_id, //分類id	
					keywords: this.keywords, //關鍵字查詢	
					ids: this.goodsids,
					shop_id: this.shop_id,
					name: this.name, //商品名称
					logoimage: this.logoimage.join(), //商品主图
					carouselimages: this.carouselimages.join(), //商品轮播图
					detailsimages: this.detailsimages.join(), //商品详情图
					mvfile: this.mvfile, //商品影片  先传空
					sp_attr: this.sp_attr.join(),
					goods_sale_id: this.saleId.join(), //销售类别id
					day: this.day, //交货天数
					num: this.num, //基本数量
					cai: this.cai, //基本用量
					size: this.size.join(';'), //基本尺寸
					unit: this.unit, //單位
					jj_unit: this.jj_unit,
					weight: this.weight, //重量
					caiamass: this.caiamass, //才积
					is_cl: this.is_cl,
					rj_type: this.rj_type,
					shopformula_id: this.shopformula_id, //公式ID
					shopwork_id: this.shopwork_id, //工作站ID
					cdbtc_ids: this.cdbtc_ids,
					spu_id: this.spu_id.join(), //商品规格1 id
					sku_id: this.sku_id.length == 1 ? this.sku_id[0] : this.sku_id.join(), //商品规格2 id
					price: this.price, //价格
					firm_id: this.firm_id, //廠商ID
					phone: this.phone, //廠商电话
					barcode: this.barcode, //条形碼
					is_up: this.is_up, //档案是否上传:0=否,1=是
					is_grounding: this.is_grounding, //是否上架:0=否,1=是
					des: this.des,
					font_color:this.font_color,
					is_main: this.is_main,
					date: this.date, //上架時間
					// enddate: this.enddate, //下架時間
					is_size: this.is_size, //尺寸开关:0=否,1=是
					end_num: this.end_num, //库存
					xd_num: this.xd_num, //限點數量
					notice: this.notice, //出货須知
					buy_notice: this.buy_notice, //購買須知
					// count: this.count, //销量
				})
				uni.hideLoading()
				if (res.code == 1) {
					this.http.toast("修改成功")
					setTimeout(() => {
						uni.navigateBack(1)
					}, 500)
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.lineorange {
		height: 30rpx;
		width: 100%;
		background-color: #ffb800;
	}

	::v-deep.u-radio-group {
		flex: none !important;
	}

	.borderhui {
		background-color: #fff;
		border-radius: 10rpx;
		// padding: 35rpx;
		box-sizing: border-box;
		margin-right: 30rpx;
		text-align: center;
	}
</style>